package com.example.neo4j.controller;

import com.example.neo4j.pojo.util.ResponseInfo;
import com.example.neo4j.service.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class ShareController {

    @Autowired
    private ShareService shareService;


    @PostMapping("/share/delete")
    @ResponseBody
    public ResponseInfo deleteShare(@RequestParam("account") String account,
                                    @RequestParam("shareid") Long shareid) {
        return shareService.deleteShare(account, shareid);
    }

    @PostMapping("/share/add")
    @ResponseBody
    public ResponseInfo addShare(
            @RequestParam("account") String account, @RequestParam("publisher") String publisher,
            @RequestParam("publisherimg") String publisherimg, @RequestParam("title") String title,
            @RequestParam("content") String content, @RequestParam("related_hobby") String related_hobby,
            @RequestParam("hobbyid") Long hobbyid,
            @RequestParam("imgurl") String imgurl, @RequestParam("address") String address) {
        return shareService.addShare(account, publisher, publisherimg, title, content, related_hobby, hobbyid, imgurl, address);
    }

    @GetMapping("/share/publish")
    public String publishShare(HttpServletRequest request, Map<String, Object> map) {
        return shareService.publishShare(request, map);
    }
}
